package com.founder.devwork.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 存储仓库信息，一个项目可对应多个仓库
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("repository")
public class Repository {

    /**
     * 仓库ID
     */
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;

    /**
     * GitLab仓库ID
     */
    @TableField("git_id")
    private Long gitId;

    /**
     * Git实例标识，只能为"beijing"或"chengdu"
     */
    @NotBlank(message = "gitInstance 不能为空")
    @Pattern(regexp = "beijing|chengdu", message = "gitInstance 只能为 'beijing' 或 'chengdu'")
    @TableField("git_instance")
    private String gitInstance;

    /**
     * 仓库名称
     */
    @NotBlank(message = "name 不能为空")
    @TableField("name")
    private String name;

    /**
     * 仓库路径
     */
    @TableField("path")
    private String path;

    /**
     * 带命名空间的路径
     */
    @TableField("path_with_namespace")
    private String pathWithNamespace;

    /**
     * 仓库最后活跃时间
     */
    @NotNull(message = "lastActivityAt 仓库最后活跃时间不能为空")
    @TableField("last_activity_at")
    private LocalDateTime lastActivityAt;

    /**
     * 仓库URL
     */
    @NotBlank(message = "webUrl 仓库URL不能为空")
    @TableField("web_url")
    private String webUrl;

    /**
     * 记录更新时间
     */
    @NotNull(message = "updatedAt 记录更新时间不能为空")
    @TableField("updated_at")
    private LocalDateTime updatedAt;

    /**
     * 仓库分支 以逗号分隔
     */
    @Size(max = 800, message = "branchIds 长度不能超过800")
    @TableField("branch_ids")
    private String branchIds;
}
